import Vue from 'vue'
import VueRouter from 'vue-router'
// 一级路由
import Login from '@/views/MyLogin'
import layout from '@/views/MyLayout'
import searchHome from '@/views/SearchHome'
import zxHome from '@/views/ZxHome'
import MyUser from '@/views/MyUser'
import Home from '@/views/MyHomeCom'
import regisite from '@/views/MyRegiste'
import favorate from '@/views/MyFavorte'
import rent from '@/views/MyRent'
import city from '@/views/MyCity'
import rentadd from '@/views/RentAdd'
import rentSearch from '@/views/RentSearch'
import map from '@/views/MyMap'

// token
// import { getToken } from '@/utils/stroage'

Vue.use(VueRouter)

const routes = [
  // 放置二级路由组件为layout 重定向为home
  {
    path: '/',
    component: layout,
    redirect: '/home',
    children: [
      {
        path: '/home',
        component: Home
      },
      {
        path: '/home/list',
        component: searchHome
      },
      {
        path: '/home/news',
        component: zxHome
      },
      {
        path: '/home/profile',
        component: MyUser
      }
    ]
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/regisite',
    component: regisite
  },
  {
    path: '/favorate',
    component: favorate
  },
  {
    path: '/rent',
    component: rent
  },
  {
    path: '/rent/add',
    component: rentadd
  },
  {
    path: '/city',
    component: city
  },
  {
    path: '/rent/search',
    component: rentSearch
  },
  {
    path: '/map',
    component: map
  }
]

const router = new VueRouter({
  routes
})
// const whiteList = ['/login', '/regisite']
// router.beforeEach((to, from, next) => {
//   const token = getToken()
//   if (token) {
//     next()
//   } else {
//     if (whiteList.includes(to.path)) {
//       next()
//     } else {
//       next('/login')
//     }
//   }
// })
export default router
